<template>
  <div class="confirmOrder">
    <a-card title="我的车票"></a-card>
    <a-table :data-source="dataList" :columns="columns" :pagination="false">
      <template #bodyCell="{ column, record }">
        <template v-if="column.dataIndex === 'operation'"></template>
        <template v-else-if="column.dataIndex === 'trainDate'">
          {{ record.trainDate }}
        </template>
        <template v-else-if="column.dataIndex === 'createTime'">
          {{ record.createTime }}
        </template>
        <template v-else-if="column.dataIndex === 'updateTime'">
          {{ record.updateTime }}
        </template>
      </template>
    </a-table>
    <a-pagination
      v-model:current="formObj.page"
      v-model:page-size="formObj.pageSize"
      align="right"
      :total="formObj.total"
      show-size-changer
      style="margin-top: 20px"
      @change="onChange"
    />
  </div>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { MyTicketApi } from '@/api/myTicket';

const columns = ref([
  //   {
  //     title: '会员id',
  //     dataIndex: 'memberId',
  //     key: 'memberId',
  //     width: 100,
  //   },
  //   {
  //     title: '乘客id',
  //     dataIndex: 'passengerId',
  //     key: 'passengerId',
  //     width: 100,
  //   },
  {
    title: '乘客姓名',
    dataIndex: 'passengerName',
    key: 'passengerName',
    width: 120,
  },
  {
    title: '日期',
    dataIndex: 'trainDate',
    key: 'trainDate',
    width: 100,
  },
  {
    title: '车次编号',
    dataIndex: 'trainCode',
    key: 'trainCode',
    width: 120,
  },
  {
    title: '箱序',
    dataIndex: 'carriageIndex',
    key: 'carriageIndex',
    width: 80,
  },
  {
    title: '排号',
    dataIndex: 'seatRow',
    key: 'seatRow',
    width: 80,
  },
  {
    title: '列号',
    dataIndex: 'seatCol',
    key: 'seatCol',
    width: 80,
  },
  {
    title: '出发站',
    dataIndex: 'startStation',
    key: 'startStation',
    width: 120,
  },
  {
    title: '出发时间',
    dataIndex: 'startTime',
    key: 'startTime',
    width: 100,
  },
  {
    title: '到达站',
    dataIndex: 'endStation',
    key: 'endStation',
    width: 120,
  },
  {
    title: '到站时间',
    dataIndex: 'endTime',
    key: 'endTime',
    width: 100,
  },
  {
    title: '座位类型',
    dataIndex: 'seatType',
    key: 'seatType',
    width: 100,
  },
  {
    title: '新增时间',
    dataIndex: 'createTime',
    key: 'createTime',
    width: 150,
  },
  {
    title: '修改时间',
    dataIndex: 'updateTime',
    key: 'updateTime',
    width: 150,
  },
]);

const formObj = ref({
  page: 1,
  pageSize: 10,
  total: 0,
});

onMounted(() => {
  getList();
});

const dataList = ref([]);

const getList = async (): Promise<void> => {
  const { data } = await MyTicketApi.query(formObj.value);
  dataList.value = data.records || [];
  formObj.value.total = data.total;
};

const onChange = (current: number, pageSize: number): void => {
  console.log(current, pageSize);
  formObj.value.page = current;
  formObj.value.pageSize = pageSize;
  getList();
};
</script>
